package com.sansui.admin.core.ctrl;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sansui.admin.common.constant.Action;
import com.sansui.admin.common.ctrl.BaseCtrl;
import com.sansui.admin.core.groups.ResourcesAdd;
import com.sansui.admin.core.groups.ResourcesUpdate;
import com.sansui.admin.core.model.Resources;
import com.sansui.admin.core.service.ResourcesService;

@RestController
@RequestMapping("/system/resources")
public class ResourcesController extends BaseCtrl {
	@Autowired
	private ResourcesService resourcesService;

	@RequiresPermissions(_RESOURCES_ROUTE + Action._ADD)
	@RequestMapping(value = Action._ADD)
	public Object add(@Validated({ ResourcesAdd.class }) Resources resources, BindingResult bindingResult) {
		return resourcesService.insertResources(resources);
	}

	@RequiresPermissions(_RESOURCES_ROUTE + Action._DELETE)
	@RequestMapping(value = Action._DELETE)
	public Object delete(String[] id) {
		return resourcesService.deleteResources(id);
	}

	@RequiresPermissions(_RESOURCES_ROUTE + Action._UPDATE)
	@RequestMapping(value = Action._UPDATE)
	public Object update(@Validated({ ResourcesUpdate.class }) Resources resources, BindingResult bindingResult) {
		return resourcesService.updateResources(resources);
	}

	@RequiresPermissions(_RESOURCES_ROUTE + Action._LIST)
	@RequestMapping(value = Action._LIST)
	public Object list() {
		return resourcesService.findResources();
	}

	@RequestMapping(value = "/findResourcesEMUByResources")
	public Object findResourcesEMUByResources() {
		System.out.println("测试为服务");
		return resourcesService.findResourcesEMUByResources();
	}

	@RequestMapping(value = Action._SPRIMARY)
	public Object selectByPrimaryKey(String id) {
		return resourcesService.selectByPrimaryKey(id);
	}

}
